<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body,html{
            width: 100%;
            height: 100%;
        }
        #box{
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            /* display: flex;
            justify-content: center;
            align-items: center; */
            background-color: rgba(0, 0, 0, 0.274);
            display: none;
        }
        #box div{
            width: 300px;
            height: 100px;
            background-color: aqua;
            position: relative;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
        }
    </style>
</head>
<body>
    <button onclick="add()">弹出层</button>
    <div id="box">
        <div><button onclick="add()">关闭</button></div>
    </div>
</body>
<script>
    var fff = false
    let box = document.getElementById('box')
    function add (){
        fff = !fff
        if(fff){
            box.style.display = 'block'
        }else{
            box.style.display = 'none'
        }
    }
</script>
</html>